@extends('admin.layout')
@section('title','新增专家')
@section('content1')
<script type="text/javascript" src="/res/js/ueditor/ueditor.config.js"></script>
<script type="text/javascript" src="/res/js/ueditor/ueditor.all.js"></script>

<div class="app_content_div" id="app_content_div_301Index">
    <h3>新增专家</h3>
</div>
<form class="form-horizontal " id="my-dropzone" method="post" action="/adm/expert/add" enctype="multipart/form-data">
    @csrf
    @method('PUT')
    <div class="form-group">
        <label for="name" class="col-sm-2 control-label"><span style="color:red;">*</span>姓名</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="name" name="name" >
        </div>
    </div>
    <div class="form-group">
        <label for="thumb" class="col-sm-2 control-label"><span style="color:red;">*</span>缩略图</label>
        <div class="col-sm-10">
            <input  id="upload_file" name="upload_file"  type="file" onchange="saveThumb()"/>
            <input type="hidden" class="form-control" id="photo" name="photo" >
            <img style="width:160px;height:200px;" alt="" id="thumb" src=""/>
        </div>
    </div>
    <div class="form-group">
        <label for="department" class="col-sm-2 control-label"><span style="color:red;">*</span>科室</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="department" name="department" >
        </div>
    </div>
    <div class="form-group">
        <label for="chenghao" class="col-sm-2 control-label"><span style="color:red;">*</span>职称</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="chenghao" name="chenghao" >
        </div>
    </div>
    <div class="form-group">
        <label for="job" class="col-sm-2 control-label"><span style="color:red;">*</span>职务</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="job" name="job" >
        </div>
    </div>
    <div class="form-group">
        <label for="hospital" class="col-sm-2 control-label"><span style="color:red;">*</span>医院</label>
        <div class="col-sm-10">
            <input type="text" class="form-control" id="hospital" name="hospital" >
        </div>
    </div>
    <div class="form-group" >
        <label for="introduction" class="col-sm-2 control-label"><span style="color:red;">*</span>简介</label>
        <div class="col-sm-10">
            <script id="introduction"  type="text/plain"></script>
            <script type="text/javascript">
                var editor1 = UE.getEditor('introduction')
            </script>
        </div>
    </div>
    <div class="form-group" >
        <label for="education" class="col-sm-2 control-label"><span style="color:red;">*</span>接受教育</label>
        <div class="col-sm-10">
            <script id="education" type="text/plain"></script>
            <script type="text/javascript">
                var editor2 = UE.getEditor('education')
            </script>
        </div>
    </div>
    <div class="form-group">
        <div class="col-sm-offset-2 col-sm-10">
            <input name="dosubmit" type="button" value="提交" class="btn_p" onclick="tijiao()" >
        </div>
    </div>
</form>


<script type="text/javascript" src="/res/js/AjaxFileUpload-master/jquery.ajaxfileupload.js"></script>

{{--<script>--}}
{{--    //预览缩略图--}}
{{--    $('#upload_file').change(function() {--}}
{{--        var imgPath = $(this)[0].value;--}}
{{--        if (imgPath === "") {--}}
{{--            alert("请选择上传图片！");--}}
{{--            return false;--}}
{{--        } else {--}}
{{--            var ext = imgPath.substring(imgPath.lastIndexOf(".") + 1).toLowerCase();--}}
{{--            if (ext !== "png" && ext !== "jpg" && ext !== "jpeg") {--}}
{{--                alert("仅支持png、jpg、jpeg格式的图片！");--}}
{{--                $(this).val("");--}}
{{--                return false;--}}
{{--            }--}}
{{--            var reader = new FileReader();--}}
{{--            reader.onload = function(evt) {--}}
{{--                $('#thumb-preview').attr('src', evt.target.result);--}}
{{--            }--}}
{{--            reader.readAsDataURL($(this)[0].files[0]);--}}
{{--        }--}}
{{--    });--}}
{{--</script>--}}

<script>
//ajax提交报错



function saveThumb(){
    var upload_file = $("#upload_file").val();
    var _token = "{{@csrf_token()}}";

    $.ajaxFileUpload({
        url:'/adm/expert/add/upload',
        type:'PUT',
        fileElementId:'img',
        dataType:'json',
        data:{
            'upload_file':upload_file,
            '_token':_token
        },
        success:function(data){
            if(data.success){
                alert("已完成");
                $('#thumb').attr('src', data['upload_file']);
            }else{
                alert(data.msg);
                $('#thumb').attr('src', '/res/images/10.jpg');
            }
        }
    })}

    function tijiao() {
        var name = $("#name").val();
        var department = $("#department").val();
        var chenghao = $("#chenghao").val();
        var job = $("#job").val();
        var hospital = $("#hospital").val();
        var introduction = UE.getEditor('introduction').getContentTxt();
        var education = UE.getEditor('education').getContentTxt();
        var photo = $("#photo").val();
        var _token ="{{@csrf_token()}}";
        $.post('/adm/expert/add',
            {
                'name':name,
                'department':department,
                'chenghao':chenghao,
                'job':job,
                'hospital':hospital,
                'introduction':introduction,
                'education':education,
                'photo':photo,
                '_token':_token
            },
            function (data){
                if(data.success){
                    alert("已完成");
                    location.href="/adm/expert";
                }
                else{
                    alert(data.msg);
                }
            },'json');
    }
</script>
@endsection
